from flask import Blueprint,request,jsonify
from api.strategy_api import*


strategy = Blueprint('strategy',__name__)
#获取策略列表
@strategy.route('/strategylist',methods=['GET'])
def getstrategy():
    userId = request.args.get(userId)
    result = get_strategy({
        "userID":userId
    })
    return jsonify(result)

#删除策略
@strategy.route('/delstrategy',methods=['GET'])
def delstrategy():
    userId = request.args.get(userId)
    straName = request.args.get(straName)
    result = del_strategy({
        "userID" : userId,
        "straName" : straName
    })
    return result

#增加新策略
@strategy.route('/addstrategy',methods=['GET'])
def addstrategy():
    userId = request.args.get(userId)
    straName = request.args.get(straName)
    result = add_strategy({
        "userID" : userId,
        "straName" : straName,
        "runTime":0,
        "rollbackTime":0
    })
    return result

#修改策略名
@strategy.route('/updatestrname',methods=['GET'])
def updatestrname():
    userId = request.args.get(userId)
    straName = request.args.get(straName)
    oldName = "改名字"
    result = update_straName({
        "userID" : userId,
        "straName" : straName,
        "oldName" : oldName
    })
    return result

#修改策略运行次数
@strategy.route('/updateruntime',methods=['GET'])
def updateruntime():
    userId = request.args.get(userId)
    straName = request.args.get(straName)
    result = update_runtime({
        "userID" : userId,
        "straName" : straName,
    })
    return result

#修改回测次数
@strategy.route('/updaterollbacktime',methods=['GET'])
def updaterollbacktime():
    userId = request.args.get(userId)
    straName = request.args.get(straName)
    result = update_rollbacktime({
        "userID" : userId,
        "straName" : straName,
    })
    return result

#修改策略代码
@strategy.route('/updatecode',methods=['GET'])
def updatecode():
    userId = request.args.get(userId)
    straName = request.args.get(straName)
    code = "java add int"
    result = update_code({
        "userID" : userId,
        "straName" : straName,
        "code" : code
    })
    return result